import VeeValidate, { Validator } from 'vee-validate'
import * as valids from '@/valids'
// 进行验证信息的自定义
const dict = {
  custom: {
    name: {
      required: '名称不能为空',
      max: '名称长度过长'
    },
    account: {
      required: '用户名不能为空',
      max: '用户名长度过长'
    },
    password: {
      required: '密码不能为空',
      min: '密码长度不少于6位',
      max: '密码长度不超过64位'
    },
    repassword: {
      required: '确认密码不能为空',
    },
    password1: {
      required: '两次密码必须一致',
    },
    accounts: {
      required: '账号不能为空'
    },
    nickName: {
      required: '昵称不能为空'
    },
    phone: {
      required: '手机号不能为空'
    },
    verification: {
      required: '验证码不能为空'
    },
    email: {
      required: '电子邮箱不能为空'
    },
    contacter: {
      required: '联系人姓名不能为空'
    },
    deviceTotal: {
      required: '授权设备数不能为空'
    },
    apps: {
      required: '至少选择一个应用'
    },
    days: {
      required: '有效期不能为空'
    },
    newpassword:{
      required: '新密码不能为空',
      confirmed: '两次密码不一致'
    },
    new_password:{
      required: '新密码不能为空',
    },
    renew_password:{
      required: '确认密码不能为空',
      confirmed: '两次密码不一致'
    },
    resetPassword:{
      required: '新密码不能为空',
    },
    sumbitRepassword:{
      required: '确认密码不能为空',
    },
    oldPassword: {
      required: '旧密码不能为空',
    },
    sms: {
      required: '验证码不能为空',
    },
    // nick:{
    //   required: false,
    // },
 
    ...valids.orgVaild,
    ...valids.resourcesVaild,
    ...valids.noticeVaild,
    ...valids.applicationVaild,
    ...valids.licenseVaild,
    organizations: {
      required: '至少选择一个客户'
    },

    contact: {
      required: '联系人不能为空'
    },
    job: {
      required: '职务不能为空'
    },
    username: {
      required: '用户名不能为空'
    },
    channelname:{
      required: '频道名称不能为空'
    },
    columnname:{
      required: '栏目名称不能为空'
    },
    tagname:{
      required: '标签名称不能为空'
    },
    roleName: {
      required: '角色名称不能为空'
    },
    role: {
      required: '角色不能为空'
    }, 
    programName: {
      required: '程序名称不能为空'
    },
    programUrl: {
      required: '更新包不能为空'
    },
    version: {
      required: '版本号不能为空'
    },
    model_id: {
      required: '适配机型不能为空'
    }, 
    suffix: {
      required: '可用后缀不能为空'
    }, 
    size: {
      required: '大小限制不能为空'
    },
    cateName: {
      required: '类别名称不能为空'
    },
    fileName: {
      required: '上传文件不能为空'
    },
    fileIcon: {
      required: '封面不能为空'
    },
    remark: {
      required: '备注不能为空'
    },
    content: {
      required: '内容不能为空'
    },
    columnname: {
      required: '栏目名称不能为空'
    },
    featuredName: {
      required: '推荐名称不能为空'
    },
    linkUrl: {
      required: '外链地址不能为空'
    },
    cover_url: {
      required: '封面图片不能为空'
    },
  }
}

// 长度为4位数的 maxLength
Validator.extend('maxLength4', {
  getMessage: field => '最大字符长度为4',
  validate: value => value.length <= 4
})
// 长度为4位数的 maxLength
Validator.extend('maxLength5', {
  getMessage: field => '最大长度为5',
  validate: value => value.length <= 5
})
// 长度为10位数的 maxLength
Validator.extend('maxLength10', {
  getMessage: field => '最大长度为10',
  validate: value => value.length <= 10
})
// 长度为16位数的 maxLength
Validator.extend('maxLength16', {
  getMessage: field => '最大长度为16',
  validate: value => value.length <= 16
})
Validator.extend('maxLength8', {
  getMessage: field => '最大字符长度为8',
  validate: value => value.length <= 8
})
// 长度为30位数的 maxLength
Validator.extend('maxLength30', {
  getMessage: field => '最大字符长度为30',
  validate: value => value.length <= 30
})
// 长度为50位数的 maxLength
Validator.extend('maxLength50', {
  getMessage: field => '最大字符长度为50',
  validate: value => value.length <= 50
})
// 长度为100位数的 maxLength
Validator.extend('maxLength100', {
  getMessage: field => '最大字符长度为100',
  validate: value => value.length <= 100
})
// 长度为120位数的 maxLength
Validator.extend('maxLength120', {
  getMessage: field => '最大字符长度为120',
  validate: value => value.length <= 120
})
// 长度为128位数的 maxLength
Validator.extend('maxLength128', {
  getMessage: field => '最大长度为128',
  validate: value => value.length <= 128
})
// 长度为300位数的 maxLength
Validator.extend('maxLength300', {
  getMessage: field => '最大字符长度为300',
  validate: value => value.length <= 300
})
// 只允许数字
Validator.extend('onlyRule0', {
  getMessage: field => '只允许数字',
  validate: value => /^[0-9]+$/.test(value)
})
// 只允许数字、小数点和-
Validator.extend('onlyRule1', {
  getMessage: field => '只允许数字、小数点和"-"字符',
  validate: value => /^[0-9\.-]+$/.test(value)
})
// 只允许数字、小数点
Validator.extend('onlyRule2', {
  getMessage: field => '只允许数字、小数点和"-"字符',
  validate: value => /^[0-9\.]+$/.test(value)
})
// 只允许数字、英文字母、小数点和"-_"字符'
Validator.extend('onlyRule3', {
  getMessage: field => '只允许数字、英文字母".-:_"字符',
  validate: value => /^[a-zA-Z0-9\.:_-]+$/.test(value)
})
// 只允许数字、英文字母、小数点和"-_"字符'
Validator.extend('onlyRule4', {
  getMessage: field => '只允许数字、英文字母".-%_"字符',
  validate: value => /^[a-zA-Z0-9\.:_%-]+$/.test(value)
})
// 只允许正整数
Validator.extend('onlyRule5', {
  getMessage: field => '必须为正整数',
  validate: value => /^[1-9]\d*$/.test(value)
})
// 值小于60
Validator.extend('onlyRule6', {
  getMessage: field => '不能大于60',
  validate: value => parseFloat(value) <= 60
})
// 只允许数字、 英文字母、小 数点 和"-_"字 符'
Validator.extend('onlyRule7', {
  getMessage: field => '只允许中文数字、英文字母"-"字符',
  validate: value => /^[a-zA-Z0-9\u4e00-\u9fa5\-]+$/.test(value)
})
// 只允许数字 0 - 120
Validator.extend('onlyRule8', {
  getMessage: field => '只允许0至120之间数字',
  validate: value => /^(?:[0-9][0-9]?|1[01][0-9]|120)$/.test(value)
})


Validator.extend('phone', {
  getMessage: field => '请输入正确的手机号',
  validate: value => value.length === 11 && /^1[3-9]\d{9}$/.test(value)
})

Validator.extend('email', {
  getMessage: field => '请输入正确的邮箱',
  validate: value => value.length < 32 &&  /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(value)
})

Validator.extend('username', {
  getMessage: field => '请输入16位以内英文加数字组合',
  validate: value => value.length < 16 &&  /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,16}$/.test(value) 
})


Validator.extend('specialCharacter', {
  getMessage: field => '存在特殊字符(只能是中文、英文或数字)',
  validate: value => /^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(value)
})

Validator.extend('size', {
  getMessage: field => '只能输入大于0的整数',
  validate: value => /^\+?[1-9][0-9]*$/.test(value)
})



Validator.extend('noChinese', {
  getMessage: field => '只能是数字和英文',
  validate: value => /^[A-Za-z0-9]+$/.test(value)
})

Validator.extend('nameLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 100
})

Validator.extend('fireNameLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 10
})

Validator.extend('remarkLength', {
  getMessage: field => '长度过长',
  validate: value => value.length <= 100
})


Validator.extend('contract_number', {
  getMessage: field => '合同编码不能超过32位',
  validate: value => value.length <= 32
})
Validator.extend('onnumber', {
  getMessage: field => '只允许数字',
  validate: value => /^[0-9]+$/.test(value)
})
Validator.extend('password', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})
Validator.extend('newpassword', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})

Validator.extend('old-password', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})



Validator.extend('new-password', {
  getMessage: field => '6~12位英文、数字、符号中的至少2种组合',
  validate: value => /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^[^\s\u4e00-\u9fa5]{6,12}$/.test(value)

})
Validator.extend('name', {
  getMessage: field => '请输入不能超过64汉字',
  validate: value => value.length <= 64  && /^[\u4E00-\u9FA5]{1,64}$/.test(value) 
})

Validator.extend('companyName', {
  getMessage: field => '机构名称只能输入中文并且不能超过64位',
  validate: value =>  /^[\u4E00-\u9FA5]{1,64}$/.test(value) 
})

Validator.extend('roleName', {
  getMessage: field => '只能输入16位以内的中文',
  validate: value => /^[\u4E00-\u9FA5]{1,16}$/.test(value)
})

// &&  /^[\u4E00-\u9FA5]{6,64}$/.test(value) 
Validator.extend('location', {
  getMessage: field => '详细地址不能超过64位',
  validate: value => value.length <= 64  
})
Validator.extend('serial', {
  getMessage: field => '主控序列号不能超过128位',
  validate: value => value.length <= 128  
})



Validator.extend('maxLength32', {
  getMessage: field => '长度不能超过32位',
  validate: value => value.length <= 32
})


Validator.extend('html', {
  getMessage: field => '内嵌html格式不正确',
  validate: value =>/^https?:\/\/(.*)/ .test(value)
})
// Validator.extend('maxLength16', {
//   getMessage: field => '长度不能超过16位',
//   validate: value => value.length <= 16
// })

Validator.extend('http', {
  getMessage: field => '外链地址格式不正确',
  validate: value =>/^https?:\/\/(.*)/ .test(value)
})

Validator.extend('suffix', {
  getMessage: field => '只能输入输入英文、数字、英文状态下的逗号',
  validate: value =>  /^[a-zA-Z0-9\,]+$/.test(value)
})

Validator.extend('hasChosen', {
  getMessage: field => '内容资源不能为空',
  validate: value => value !== '已选择0个资源'
})


Validator.extend('nickName', {
  getMessage: field => '昵称只能输入8位以内的中文',
  validate: value => /^[\u4E00-\u9FA5]{1,8}$/.test(value)
})
export const Config = {
  fieldsBagName: 'veefields'
}
Validator.localize('en', dict)
export default VeeValidate
